package FrameWork;

import java.awt.Color;
import java.awt.Graphics;

import Main.SpaceGame;
import World.World;

public class Cursor 
{
	int desStartX = -1, desStartY = -1;
	SpaceGame main;
	int x = 15,y = 15;
	int width = 1;
	int height = 1;
	boolean active = false;
	boolean designating = false;
	public Cursor(SpaceGame main)
	{
		this.main = main;
	}
	
	public void draw(Graphics g)
	{
		if (active)
		{	
			drawDesignationSquare(g);
			g.setColor(Color.green);
			g.drawRect(x*10, y*10, width*10-1, height*10-1);
		}
	}
	
	public void moveRight()
	{
		if (x < World.worldXSize-1)
		{
			x+=1;
			if (x >= (main.camera.pixelX/10)+(SpaceGame.windowXSize/10-20))
				main.camera.cameraRight();
		}
	}
	
	public void moveLeft()
	{
		if (x > 0)
		{
			x-=1;
			if (x <= main.camera.pixelX/10-1)
				main.camera.cameraLeft();
		}
	}
	
	public void moveUp()
	{
		if (y > 3)
		{
			y-=1;
			if (y <= main.camera.pixelY/10+2)
				main.camera.cameraUp();
		}
	}
	
	public void moveDown()
	{
		if (y < World.worldYSize-1)
		{
			y+=1;
			if (y >= (main.camera.pixelY/10)+(SpaceGame.windowYSize/10-10))
				main.camera.cameraDown();
		}
	}
	
	public void setActive(boolean active)
	{
		this.active = active;
		if (active)
			main.camera.setCanMove(false);
		else
		{
			main.camera.setCanMove(true);
		}
		x = main.camera.getPixelX()/10+50; y = main.camera.getPixelY()/10+30;
	}
	
	public boolean isActive()
	{
		return active;
	}
	
	public int getX()
	{
		return x;
	}
	
	public int getY()
	{
		return y;
	}
	
	public boolean isDesignating()
	{
		return designating;
	}
	
	public void setDesignating(boolean a)
	{
		this.designating = a;
	}
	
	public void setDesStartCoords(int x, int y)
	{
		this.desStartX = x;
		this.desStartY = y;
	}
	
	public void drawDesignationSquare(Graphics g)
	{
		if (designating && desStartX >= 0 && desStartY >= 0)
		{
			g.setColor(Color.blue);
			if (x >= desStartX)
			{
				if (y >= desStartY)
					g.drawRect(desStartX*10, desStartY*10, (x-desStartX)*10+9, (y-desStartY)*10+9);
				else
					g.drawRect(desStartX*10, y*10, (x-desStartX)*10+9, (desStartY-y)*10+9);
			}
			else
			{
				if (y <= desStartY)
					g.drawRect(x*10, y*10, (desStartX-x)*10+9, (desStartY-y)*10+9);
				else
					g.drawRect(x*10, desStartY*10, (desStartX-x)*10+9, (y-desStartY)*10+9);
			}
		}
		/**
		 * Above is the stuff for the blue box around designations
		 */
	}
	
	public void setCursorSize(int width,int height)
	{
		this.width = width;
		this.height = height;
	}
	
	public int getWidth()
	{
		return width;
	}
	
	public int getHeight()
	{
		return height;
	}
}
